﻿using SanctusSoftware.Music.Chords;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Diagnostics;

namespace SanctusSoftware.Music.Chords.Tests
{


  /// <summary>
  ///This is a test class for ChordTransposerTest and is intended
  ///to contain all ChordTransposerTest Unit Tests
  ///</summary>
  [TestClass()]
  public class ChordTransposerTest
  {


    private TestContext testContextInstance;

    /// <summary>
    ///Gets or sets the test context which provides
    ///information about and functionality for the current test run.
    ///</summary>
    public TestContext TestContext
    {
      get
      {
        return testContextInstance;
      }
      set
      {
        testContextInstance = value;
      }
    }

    #region Additional test attributes
    // 
    //You can use the following additional attributes as you write your tests:
    //
    //Use ClassInitialize to run code before running the first test in the class
    //[ClassInitialize()]
    //public static void MyClassInitialize(TestContext testContext)
    //{
    //}
    //
    //Use ClassCleanup to run code after all tests in a class have run
    //[ClassCleanup()]
    //public static void MyClassCleanup()
    //{
    //}
    //
    //Use TestInitialize to run code before running each test
    //[TestInitialize()]
    //public void MyTestInitialize()
    //{
    //}
    //
    //Use TestCleanup to run code after each test has run
    //[TestCleanup()]
    //public void MyTestCleanup()
    //{
    //}
    //
    #endregion

    [TestMethod]
    public void GetChordMatchPercentWordsTest()
    {

      string[] songWords = new string[] {
      "Amazing", "Grace", "But", "Found", "Blind",
      "Heart", "Fear", "Did", "Appear", "Hour", "First", "Believed",
      "Dangers", "Have", "Already", "Come", "Hath", "Brought", "Far", "Home",
      "Been", "Bright", "As", "Days", "God's", "Begun",
      "Alleluia"

      };

      foreach (string songWord in songWords)
      {
        ChordMatchPercentTestHelper(songWord, true, false);
      }


    }

    /// <summary>
    ///A test for GetChordMatchPercent
    ///</summary>
    [TestMethod()]
    public void GetChordMatchPercent_MatchStandardChords_Check()
    {


      string[] noteLetters = new string[] { "A", "B", "C", "D", "E", "F", "G" };
      string[] pitchModifiers = new string[] { "", "#", "♯", "b", "♭", "##", "♯♯", "bb", "♭♭" };
      string[] baseChordTypes = new string[] { "", "m", "dim", "°", "aug", "+" };

      foreach (string note in noteLetters)
      {
        foreach (string baseChordType in baseChordTypes)
        {
          foreach (string pitchModifier in pitchModifiers)
          {
            ChordMatchPercentTestHelper(note + baseChordType + pitchModifier, false, true);
          }
        }
      }

      ChordMatchPercentTestHelper("Ebb", true, true);
      ChordMatchPercentTestHelper("Cm", true, true);




    }


    [TestMethod]
    public void GetChordMatchPercent_Chorus_SpelledCorrectly_Check()
    {
      ChordMatchPercentTestHelper("Chorus", true, false);
    }

    [TestMethod]
    public void GetChordMatchPercent_Chorus_NotSpelledCorrectly_Check()
    {
      ChordMatchPercentTestHelper("Chorus", false, false);
    }

    [TestMethod]
    public void GetChordMatchPercent_ChorusBrackets_SpelledCorrectly_Check()
    {
      ChordMatchPercentTestHelper("[Chorus]", true, false);
    }

    [TestMethod]
    public void GetChordMatchPercent_ChorusBrackets_NotSpelledCorrectly_Check()
    {
      ChordMatchPercentTestHelper("[Chorus]", false, false);
    }

    [TestMethod]
    public void GetChordMatchPercent_BridgeBrackets_SpelledCorrectly_Check()
    {
      ChordMatchPercentTestHelper("[Bridge]", true, false);
    }

    [TestMethod]
    public void GetChordMatchPercent_BridgeBrackets_NotSpelledCorrectly_Check()
    {
      ChordMatchPercentTestHelper("[Bridge]", false, false);
    }

    #region Helper Methods

    public void ChordMatchPercentTestHelper(string chord, bool? isSpelledCorrectly, bool isChord)
    {
      Debug.WriteLine(chord);
      decimal matchPercent = ChordTransposer.GetChordMatchPercent(chord, isSpelledCorrectly);
      if (isChord)
      {
        Assert.IsTrue(matchPercent > .5m, "'" + chord + "' should be a chord but the match percent was " + matchPercent.ToString("P2"));
      }
      else
      {
        Assert.IsFalse(matchPercent > .5m, "'" + chord + "' should NOT be a chord but the match percent was " + matchPercent.ToString("P2"));
      }

    }

    #endregion


  }
}
